home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 80 / CD Actual 80 Julio-Agosto 2003.iso / Linux / LinuxGazette / lg / issue17 / source / MJH3HolePaper.sl < prev    next >
Encoding:
Text File  |  2002-08-14  |  3.2 KB  |  108 lines

  1. /*
  2.  * Three Holed, lined paper
  3.  * (C) 1997 by Michael J. Hammel
  4.  *
  5.  * hcolor         horizontal line color
  6.  * vcolor         vertical line color
  7.  * hfreq          number of horizontal bars
  8.  * vfreq          number of vertical bars
  9.  * skip           number of horizontal bars to skip (no lines)
  10.  * paper_height   default is 11 (as in inches)
  11.  * paper_width    default is 8.5 (as in inches)
  12.  * density        width of lines on paper
  13.  * holeoffset     percentage of paper_width from left edge for hole centers
  14.  * holeradius     radius of holes relative to paper_width
  15.  * hole1          horizontal line number where hole 1 should be made
  16.  * hole2          horizontal line number where hole 2 should be made
  17.  * hole3          horizontal line number where hole 3 should be made
  18.  */
  19. #include "rmannotes.sl"
  20.  
  21. surface
  22. MJH3HolePaper(
  23.    color hcolor       = color "rgb" (0, 0, .7);
  24.    color vcolor       = color "rgb" (.7, 0, 0);
  25.    float hfreq        = 34;
  26.    float vfreq        = 6;
  27.    float skip         = 4;
  28.    float paper_height = 11;
  29.    float paper_width  = 8.5;
  30.    float density      = .03525;
  31.    float holeoffset   = .09325;
  32.    float holeradius   = .01975;
  33.    float hole1        = 2.6;
  34.    float hole2        = 18;
  35.    float hole3        = 31.25;
  36. )
  37. {
  38.    color surface_color;
  39.    float hblock = paper_height/hfreq;
  40.    float horiz;
  41.    float tt,ss;
  42.    float min, max, val;
  43.    float thole,shole;
  44.    float vblock = paper_width/vfreq;
  45.    point pos, hpos;
  46.  
  47.  
  48.    /* Initialize the surface color to the default surface color */
  49.    surface_color = Cs;
  50.  
  51.    /*
  52.     * Layer 1 - horizontal stripes.  There is one stripe for every
  53.     * horizontal block.  The stripe is "density" thick and starts at the top of
  54.     * each block, except for the first "skip" blocks.
  55.     */
  56.    tt = t*paper_height;
  57.    for ( horiz=skip; horiz<hfreq; horiz=horiz+1 )
  58.    {
  59.       min = horiz*hblock;
  60.       max = min+density;
  61.       val = smoothstep(min, max, tt);
  62.       if ( val != 0 && val != 1 )
  63.          surface_color = mix(hcolor, Cs, val);
  64.    }
  65.  
  66.    /* Layer 2 - vertical stripe */
  67.    ss = s*paper_width;
  68.    min = vblock;
  69.    max = min+density;
  70.    val = smoothstep(min, max, ss);
  71.    if ( val != 0 && val != 1 )
  72.       surface_color = mix(vcolor, Cs, val);
  73.  
  74.    /*
  75.     * The 3 punch holes along the side.  We compute the center for each
  76.     * hole and then the distance the current s,t coordinates are from
  77.     * that center.  If it is less than the holes radius then we set the
  78.     * opacity level for the incident ray to be completely transparent.
  79.     */
  80.  
  81.    shole = holeoffset*paper_width;
  82.    ss  = s*paper_height;
  83.    tt  = t*paper_height;
  84.    pos = (ss,tt,0);
  85.  
  86.    /* First Hole */
  87.    thole = hole1*hblock;
  88.    hpos  = (shole, thole, 0);
  89.    Oi    = filterstep (holeradius*paper_width, distance(pos,hpos));
  90.  
  91.    /* Second Hole */
  92.    thole = hole2*hblock;
  93.    hpos = (shole, thole, 0);
  94.    Oi *= filterstep (holeradius*paper_width, distance(pos,hpos));
  95.  
  96.    /* Third Hole */
  97.    thole = hole3*hblock;
  98.    hpos = (shole, thole, 0);
  99.    Oi *= filterstep (holeradius*paper_width, distance(pos,hpos));
  100.  
  101.    /*
  102.     * The output values - Ci is the incident ray, the ray leading 
  103.     * to the camera.  We make this a dull surface, with very little
  104.     * reflective qualities.
  105.     */
  106.    Ci = surface_color;
  107. }
  108.